﻿using System;
using System.Web.Configuration;
using System.Data;

public partial class manager_temt_TaskFp_viewKh : System.Web.UI.Page
{
    public string Html_Dept = "";
    public string Html_Dept_Detail = "";
    public string Html_Dept_zxgw = "";
    public string Html_Dept_Detail_zxgw = "";

    public int taskid = 0;
    public int type = 0;
    DBHelper db = new DBHelper(WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        taskid = Convert.ToInt32(Request.QueryString["id"]);

        Edit_Id.Value = taskid.ToString();
        if (!IsPostBack)
        {
           
            loadEditData(taskid);
        }
    }
    private void loadData_ZXR(string dept)
    {
        Html_Dept_Detail_zxgw += "<div class=\"box-body\">";
        Html_Dept_Detail_zxgw += "<table id=\"table_zxgw\" class=\"table table-bordered table-striped\">";
        Html_Dept_Detail_zxgw += "<thead>";
        Html_Dept_Detail_zxgw += "<tr>";
        Html_Dept_Detail_zxgw += "<th></th>";
        Html_Dept_Detail_zxgw += "<th class=\"col-sm-7\">名称</th>";
        Html_Dept_Detail_zxgw += "<th class=\"col-sm-3\">当前在岗</th>";
        Html_Dept_Detail_zxgw += "</tr>";
        Html_Dept_Detail_zxgw += "</thead>";
        Html_Dept_Detail_zxgw += "<tbody>";

      
        DataTable dt = db.getList("v_dict_dept_position", "*", "dept=" + dept , "bh");
        foreach (DataRow dr in dt.Rows)
        {
            Html_Dept_Detail_zxgw += "<tr style=\"cursor:pointer\" onclick=\"SetZxgw('" + dr["id"].ToString() + "','" + dr["mc"].ToString() + "|" + dr["userName"].ToString() + "')\">";

            Html_Dept_Detail_zxgw += "<td>" + dr["id"].ToString() + "</td>";
            switch (dr["type"].ToString())
            {
                case "1":
                    Html_Dept_Detail_zxgw += "<td><b>" + dr["mc"].ToString() + "</b></td>";

                    break;
                case "2":
                    Html_Dept_Detail_zxgw += "<td style=\"padding-left:30px;\">" + dr["mc"].ToString() + "</td>";

                    break;
                case "3":
                    Html_Dept_Detail_zxgw += "<td style=\"padding-left:50px;\">" + dr["mc"].ToString() + "</td>";

                    break;
            }
            Html_Dept_Detail_zxgw += "<td><b>" + dr["userName"].ToString() + "</b></td>";
            Html_Dept_Detail_zxgw += "</tr>";
        }
        Html_Dept_Detail_zxgw += "</tbody>";
        Html_Dept_Detail_zxgw += "</table>";
        Html_Dept_Detail_zxgw += "</div>";
        Html_Dept_Detail_zxgw += "</div>";

    }

    private void loadEditData(int sid)
    {
        string sql = "select * from v_dict_dept_position_Task where id=" + sid;
        DataTable dt = db.getList(sql);
        if (dt.Rows.Count == 1)
        {
            txt_title.Value = dt.Rows[0]["title"].ToString();
            txt_detail.Value = dt.Rows[0]["detail"].ToString();
            ZRR_psid_mc.Value = dt.Rows[0]["Ry_Kh_Gw"].ToString() + "|" + dt.Rows[0]["Ry_Kh_Mc"].ToString();
            ZRR_psid.Value = dt.Rows[0]["Ry_Kh"].ToString();
            loadData_ZXR(dt.Rows[0]["dept_kh"].ToString());
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string taskid = Edit_Id.Value;
        string userName = Session[AppConfig.SESSION_USER_NAME].ToString();
        string zxr_psid = ZRR_psid.Value;

        string userpsid = Session[AppConfig.SESSION_USER_PSID].ToString();
        int i = 0;
        if (taskid != "0" && zxr_psid != "0")
        {
            string sql = "update A_Task set [RY_Kh]='" + zxr_psid + "' where RealId=" + taskid;
            i = db.executeNoneQuery(sql);
            sql = "update dict_dept_position_Task set [RY_Kh]='" + zxr_psid + "' where id=" + taskid;
            i = db.executeNoneQuery(sql);
            if (i > 0)
            {
                Response.Write("<script>window.close();</script>");
            }
            else
            {
                Response.Write(CommonHelper.MsgAndRedirectN("任务验收失败请核对信息", "Default.aspx"));
            }
        }
        else
        {
            Response.Write(CommonHelper.MsgAndRedirectN("任务并未分配", "Default.aspx"));
        }

    }


}